﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Admin_Default"
    Title="Default" MasterPageFile="~/Shared/DefaultMaster.master" %>

<%@ Register Assembly="Microsoft.Practices.Web.UI.WebControls" Namespace="Microsoft.Practices.Web.UI.WebControls"
    TagPrefix="pp" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="content" ContentPlaceHolderID="DefaultContent" Runat="Server">
        <cc1:ToolkitScriptManager ID="ToolkitScriptManagerAdmin" runat="server" AllowCustomErrorsRedirect="False">
        </cc1:ToolkitScriptManager>
        <br/> 
    <cc1:TabContainer ID="TabContainerAdmin" runat="server" ActiveTabIndex="1">
        <cc1:TabPanel ID="TabPanelCustomer" runat="server" HeaderText="Administraci&#243;n de clientes">
            <ContentTemplate>
                <pp:ObjectContainerDataSource ID="CustomerContainerDataSource" runat="server" DataObjectTypeName="Metro.Admin.BusinessEntities.Customer" OnDeleted="CustomerContainerDataSource_Deleted" OnUpdated="CustomerContainerDataSource_Updated" />
                <pp:ObjectContainerDataSource ID="CityContainerDataSource" runat="server" DataObjectTypeName="Metro.Admin.BusinessEntities.City" />
                  <table>
                    <tr>
                        <td style="width: 100px">
                            <asp:Label ID="lblName" runat="server" Text="Nombre:"></asp:Label></td>
                        <td style="width: 19px">
                            <asp:TextBox ID="txtName" runat="server" Width="106px"></asp:TextBox><asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName"
                                ErrorMessage="*" ValidationGroup="Customer"></asp:RequiredFieldValidator></td>
                        <td style="width: 100px">
                            <asp:Label ID="lblLastName" runat="server" Text="Apellido:"></asp:Label></td>
                        <td style="width: 100px">
                            <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
                        <td rowspan="4" colspan="100" style="vertical-align: middle; text-align: center">
                            <asp:UpdateProgress ID="SearchUpdateProgress" runat="server" DynamicLayout="False">
                                 <ProgressTemplate>
                                      <asp:Image ID="ProcessingImage" runat="server" ImageUrl="~/images/loading.gif" /> <strong>Processing...</strong>
                                </ProgressTemplate>
                            </asp:UpdateProgress>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px; height: 20px">
                            <asp:Label ID="lblCustomerType" runat="server" Text="Tipo de cliente:" Width="115px"></asp:Label></td>
                        <td style="width: 19px; height: 20px">
                            <asp:DropDownList ID="ddlCustomerType" runat="server">
                                <asp:ListItem Value="C">Cambiario</asp:ListItem>
                                <asp:ListItem Value="O" >OPCF</asp:ListItem>
                            </asp:DropDownList>
                            </td>
                        <td style="width: 100px; height: 20px">
                            <asp:Label ID="lblDocType" runat="server" Text="Tipo Documento:" Width="115px"></asp:Label></td>
                        <td style="width: 100px; height: 20px">
                            <asp:DropDownList ID="ddlDocType" runat="server">
                                <asp:ListItem>NIT</asp:ListItem>
                                <asp:ListItem>CC</asp:ListItem>
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">
                            <asp:Label ID="lblDoc" runat="server" Text="Documento:"></asp:Label></td>
                        <td style="width: 19px;">
                            <asp:TextBox ID="txtDocument" runat="server" Width="106px"></asp:TextBox><asp:RequiredFieldValidator ID="rfvDocument" runat="server" ControlToValidate="txtDocument"
                                ErrorMessage="*" ValidationGroup="Customer"></asp:RequiredFieldValidator></td>
                        <td style="width: 100px;">
                            <asp:Label ID="lblState" runat="server" Text="Estado:"></asp:Label></td>
                        <td style="width: 100px;">
                            <asp:DropDownList ID="ddlState" runat="server">
                                <asp:ListItem Selected="True" Value="A">Active</asp:ListItem>
                                <asp:ListItem Value="I">Inactive</asp:ListItem>
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td style="width: 100px; height: 20px">
                            <asp:Label ID="lblCommission" runat="server" Text="Comisi&oacute;n:"></asp:Label></td>
                        <td style="width: 19px; height: 20px">
                            <asp:TextBox ID="txtCommission" runat="server" Width="74px"></asp:TextBox>
                            <cc1:MaskedEditExtender ID="CommissionMaskedEditExtender" runat="server" DisplayMoney="Left"
                                Mask="99.99" MaskType="Number" TargetControlID="txtCommission">
                            </cc1:MaskedEditExtender>
                        </td>
                        <td style="width: 100px; height: 20px">
                            <asp:Label ID="lblCity" runat="server" Text="Ciudad:"></asp:Label></td>
                        <td style="width: 100px; height: 20px">
                            <asp:DropDownList ID="ddlCity" runat="server" DataTextField="Name" DataValueField="Id">
                            </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="rfvCity" runat="server" ControlToValidate="ddlCity"
                                ErrorMessage="*" ValidationGroup="Customer"></asp:RequiredFieldValidator></td>
                    </tr>
                </table>
                <asp:Button ID="btnSearch" runat="server" Text="Buscar" CausesValidation="False" Visible="False" />
                <asp:Button ID="btnAdd" runat="server" Text="Agregar" OnClick="btnAdd_Click" ValidationGroup="Customer" /><br />
                <asp:UpdatePanel ID="ResultsUpdatePanel" runat="server">
                    <ContentTemplate>
                        <br />
                        <asp:GridView ID="customerGrid" runat="server" BackColor="White" BorderColor="White"
                    BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" GridLines="None" AutoGenerateColumns="False" CellSpacing="1" DataSourceID="CustomerContainerDataSource" DataKeyNames="Id">
                    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                            <Columns>
                                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" CausesValidation="False" ButtonType="Image" CancelImageUrl="~/images/cross.png" DeleteImageUrl="~/images/delete.png" EditImageUrl="~/images/pencil.png" UpdateImageUrl="~/images/tick.png"/>
                                <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" Visible="False" />
                                <asp:BoundField DataField="Name" HeaderText="Nombre" SortExpression="Name" />
                                <asp:BoundField DataField="SureName" HeaderText="Apellido" SortExpression="SureName" />
                                <asp:TemplateField HeaderText="Nemo" SortExpression="TechnicalName">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="txtTechName" runat="server" MaxLength="5" Text='<%# Bind("TechnicalName") %>'
                                            Width="76px"></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblTechName" runat="server" Text='<%# Bind("TechnicalName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Tipo Documento" SortExpression="DocumentType">
                                    <EditItemTemplate>
                                        <asp:Label ID="lblDocumentType" runat="server" Text='<%# Bind("DocumentType") %>'></asp:Label>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblDocumentType" runat="server" Text='<%# Bind("DocumentType") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Tipo Cliente" SortExpression="StringCustomerType">
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="ddlCustomerType" runat="server" SelectedValue='<%# Bind("StringCustomerType") %>' >
                                            <asp:ListItem>Cambiario</asp:ListItem>
                                            <asp:ListItem>OPCF</asp:ListItem>
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblCusType" runat="server" Text='<%# Bind("StringCustomerType") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="DocumentNumber" HeaderText="Documento" SortExpression="DocumentNumber" />
                                <asp:BoundField DataField="CityId" HeaderText="CityId" SortExpression="CityId" Visible="False" />
                                <asp:TemplateField HeaderText="Ciudad">
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="ddlCityEdit" runat="server" DataTextField="Name" DataValueField="Id" DataSourceID="CityContainerDataSource" SelectedValue='<%# Bind("CityId") %>' >
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblCityItem" runat="server" Text='<%# Bind("CityName") %>' ></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="Position" HeaderText="Posici&#243;n" SortExpression="Position" ReadOnly="True" DataFormatString="{0:C}" />
                                <asp:BoundField DataField="SellCredit" HeaderText="Cupo Venta" SortExpression="SellCredit" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="BuyCredit" HeaderText="Cupo Compre" SortExpression="BuyCredit" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="Commission" HeaderText="Comisi&#243;n" SortExpression="Commission" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="AvgSell" HeaderText="Prom Venta" SortExpression="AvgSell" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="AvgBuy" HeaderText="Prom Compra" SortExpression="AvgBuy" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="TransitSellCredit" HeaderText="Cupo Canje Venta" SortExpression="TransitSellCredit" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="TransitBuyCredit" HeaderText="Cupo Canje Compra" SortExpression="TransitBuyCredit" ReadOnly="True" DataFormatString="{0:C}"/>
                                <asp:BoundField DataField="Profit" HeaderText="Utilidad" SortExpression="Profit" ReadOnly="True" Visible="False" DataFormatString="{0:C}"/>
                                <asp:CheckBoxField DataField="PayTaxes" HeaderText="Impuestos" SortExpression="PayTaxes" ReadOnly="True"/>
                                <asp:TemplateField HeaderText="Estado" SortExpression="StringState">
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="ddlState" runat="server" SelectedValue='<%# Bind("StringState") %>'>
                                            <asp:ListItem Selected="True" Value="A">Active</asp:ListItem>
                                            <asp:ListItem Value="I">Inactive</asp:ListItem>
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblState" runat="server" Text='<%# Bind("StringState") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                </asp:GridView>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <br />
            <center>
                </center>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel ID="TabPanelUser" runat="server" HeaderText="Administraci&#243;n de usuarios">
            <ContentTemplate>
                <pp:ObjectContainerDataSource ID="UserContainerDataSource" runat="server" DataObjectTypeName="Metro.Admin.BusinessEntities.User" OnDeleted="UserContainerDataSource_Deleted" OnUpdated="UserContainerDataSource_Updated" />
                <pp:ObjectContainerDataSource ID="CustomersContainerDataSource" runat="server" DataObjectTypeName="Metro.Admin.BusinessEntities.Customer" />
                <br />
                <br />
                <p><b>Agregar nuevo usuario</b></p>   
                <p>
                    <table >
                        <tr>
                            <td >Nombre:</td>
                            <td >
                                <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvUserName" runat="server" ControlToValidate="txtUserName"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>Apellido:</td>
                            <td>
                                <asp:TextBox ID="txtUserLastName" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvLastName" runat="server" ControlToValidate="txtUserLastName"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>Login:</td>
                            <td >
                                <asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvLogin" runat="server" ControlToValidate="txtLogin"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>Password:</td>
                            <td >
                                <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>Repetir password:</td>
                            <td>
                                <asp:TextBox ID="txtRepeatPassword" runat="server" TextMode="Password"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvRepeatPassword" runat="server" ControlToValidate="txtRepeatPassword"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                                <asp:CompareValidator ID="cvPassword" runat="server" ControlToCompare="txtPassword"
                                    ControlToValidate="txtRepeatPassword" ErrorMessage="Password doesn't match" ForeColor="White"
                                    ValidationGroup="User" ValueToCompare="Text"></asp:CompareValidator>
                                <cc1:ValidatorCalloutExtender ID="vcePasswordRepeat" runat="server" Enabled="True"
                                    TargetControlID="cvPassword">
                                </cc1:ValidatorCalloutExtender>
                            </td>
                        </tr>
                        <tr>
                            <td>Cliente:</td>
                            <td><asp:DropDownList ID="ddlCustomer" runat="server" DataTextField="Name" DataValueField="Id" DataSourceID="CustomersContainerDataSource">
                                </asp:DropDownList>&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td>Tipo Usuario:</td>
                            <td><asp:DropDownList ID="ddlUserType" runat="server">
                                    <asp:ListItem Value="Adm">Adm</asp:ListItem>
                                    <asp:ListItem Value="RiskAdm">RiskAdm</asp:ListItem>
                                    <asp:ListItem Value="CustomerAdm">CustomerAdm</asp:ListItem>
                                    <asp:ListItem Value="UserAdm">UserAdm</asp:ListItem>
                                    <asp:ListItem Value="Trader">Trader</asp:ListItem>
                                    <asp:ListItem Value="User">User</asp:ListItem>
                                    <asp:ListItem Value="DeskPpal">DeskPpal</asp:ListItem>
                                    <asp:ListItem Value="SalesForce">SalesForce</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td>Email:</td>
                            <td><asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                                <asp:RegularExpressionValidator ID="revEmail" runat="server" ControlToValidate="txtEmail"
                                    ErrorMessage="Email doesn't match" Display="Dynamic" ForeColor="White" ValidationExpression="^\w+[\w-\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$" ValidationGroup="User"></asp:RegularExpressionValidator> 
                                <asp:RequiredFieldValidator ID="rfvEmail" runat="server" ControlToValidate="txtEmail"
                                    Display="Dynamic" ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                                <cc1:ValidatorCalloutExtender ID="vceEmail" runat="server" TargetControlID="revEmail" Enabled="True">
                                </cc1:ValidatorCalloutExtender>
                            </td>
                        </tr>
                        <tr>
                            <td>Pregunta de recordatorio:</td>
                            <td>
                                <asp:TextBox ID="txtPasswordQuestion" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvPasswordQuestion" runat="server" ControlToValidate="txtPasswordQuestion"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>Respuesta de recordatorio:</td>
                            <td>
                                <asp:TextBox ID="txtPasswordAnswer" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvPasswordAnswer" runat="server" ControlToValidate="txtPasswordAnswer"
                                    ErrorMessage="*" ValidationGroup="User"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Button ID="btnAddUser" runat="server" Text="Agregar" OnClick="btnAddUser_Click" ValidationGroup="User" /></td>
                            <td>
                            </td>
                        </tr>
                    </table>
                    <b></b>
                </p>
                <p><b>Lista de usuarios</b></p>
                <asp:GridView ID="userGrid" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataSourceID="UserContainerDataSource" GridLines="None" DataKeyNames="Id">
                    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Image" CancelImageUrl="~/images/cross.png" DeleteImageUrl="~/images/delete.png" EditImageUrl="~/images/pencil.png" UpdateImageUrl="~/images/tick.png" />
                        <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" Visible="False" />
                        <asp:BoundField DataField="Name" HeaderText="Nombre" SortExpression="Name" />
                        <asp:BoundField DataField="LastName" HeaderText="Apellido" SortExpression="LastName" />
                        <asp:BoundField DataField="Login" HeaderText="Login" SortExpression="Login" />
                        <asp:TemplateField HeaderText="Tipo usuario" SortExpression="UserTypeString">
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlUserType" runat="server" SelectedValue='<%# Bind("UserTypeString") %>' >
                                    <asp:ListItem Value="Adm">Adm</asp:ListItem>
                                    <asp:ListItem Value="RiskAdm">RiskAdm</asp:ListItem>
                                    <asp:ListItem Value="CustomerAdm">CustomerAdm</asp:ListItem>
                                    <asp:ListItem Value="UserAdm">UserAdm</asp:ListItem>
                                    <asp:ListItem Value="Trader">Trader</asp:ListItem>
                                    <asp:ListItem Value="User">User</asp:ListItem>
                                    <asp:ListItem Value="DeskPpal">DeskPpal</asp:ListItem>
                                    <asp:ListItem Value="SalesForce">SalesForce</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblUserType" runat="server" Text='<%# Bind("UserTypeString") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Email" SortExpression="Email">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtEmail" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
                                <asp:RegularExpressionValidator ID="revEmail" runat="server" ControlToValidate="txtEmail"
                                    Display="Dynamic" ErrorMessage="Email doesn't match" ForeColor="White" ValidationExpression="^\w+[\w-\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$"
                                    ValidationGroup="User"></asp:RegularExpressionValidator>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblEmail" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Cliente">
                            <EditItemTemplate><asp:DropDownList ID="ddlCustomer" runat="server" DataTextField="Name" DataValueField="Id" DataSource="<%# ShowCustomers() %>" SelectedValue='<%# Bind("CustomerId") %>' >
                            </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblCustomer" runat="server" Text='<%# Bind("CustomerName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="CustomerName" HeaderText="CustomerName" SortExpression="CustomerName" Visible ="False" />
                        <asp:BoundField DataField="PasswordQuestion" HeaderText="Pregunta de recordatorio" SortExpression="PasswordQuestion" />
                        <asp:BoundField DataField="PasswordAnswer" HeaderText="Respuesta de recordatorio" SortExpression="PasswordAnswer" />
                    </Columns>
                    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                </asp:GridView>
            </ContentTemplate>
        </cc1:TabPanel>
    </cc1:TabContainer>
</asp:Content>
